import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseSubPackage from "../../core/subPackage/BaseSubPackage";
import { DataCallback, ResultState } from "../../SDKDefine";

@registerClass('WXSubPackage')
export class WXSubPackage extends BaseSubPackage {
 

    loadSubpackage(subname: string, callback: DataCallback, onProgress?: (finished: number, total: number, item?: any) => void) {

        const loadTask = this.sdk.loadSubpackage({
            name: subname, // name 可以填 name 或者 root
            success: (res: any) => {
                // 分包加载成功后通过 success 回调
                callback(ResultState.YES, null)
            },
            fail: (res: any) => {
                // 分包加载失败通过 fail 回调
                // console.log(' loadSubpackage fail res ', res, ' subname ', subname)
                callback(ResultState.NO, null)
            },
        });
        if (loadTask) {
            loadTask.onProgressUpdate((res: { progress: number, }) => {
                callback(ResultState.PROGRESS, res.progress)
            })
        } else {

        }



    }

}